package com.yuxi.Dao.Impl;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.format.datetime.standard.InstantFormatter;
import org.springframework.stereotype.Repository;

import com.yuxi.Config.ConfigStatic;
import com.yuxi.Config.UserTableStatic;
import com.yuxi.Dao.InformationDao;
import com.yuxi.Entity.FirstCheckExcel;
import com.yuxi.Entity.Information;
import com.yuxi.Entity.InformationPort;
import com.yuxi.Entity.Position;
import com.yuxi.Entity.PrisonRole;
import com.yuxi.Entity.PrisonStructure;
import com.yuxi.Entity.TaskInformationView;
import com.yuxi.Entity.UserInfo;
import com.yuxi.Request.DateQuery;
import com.yuxi.Request.InformationQuery;
import com.yuxi.Request.Page;
import com.yuxi.Response.InfoCount;
import com.yuxi.view.UserPowerView;

@Repository
public class InformationDaoImpl extends BaseDaoImpl<Serializable, Serializable> implements InformationDao {
	private Logger logger = LoggerFactory.getLogger(InformationDaoImpl.class);

	public InformationDaoImpl() {
		super(Information.class);
	}

	@Override
	public Information getInformationById(Integer informationId) {
		return (Information) super.get(informationId);
	}

	@Override
	public Information addInformation(Information i) {
		return (Information) super.addAndReturn(i);
	}

	@Override
	public void modifyInformation(Information i) {		
		super.update(i);
	}

	@Override
	public void deleteInformation(Information i) {
		super.delete(i);
	}

	@Override
	public Page<Information> getInfomationAll(Page p) {
		try {
			String hql = "from Information";
			p = super.splitPageQuery(hql, p, null);
			logger.info("查询所有信息成功");
			return p;
		} catch (Exception e) {
			logger.error("查询所有信息失败");
			return null;
		}

	}

	@Override
	public Page<Information> getInfomationByClassificationId(Page p, int id) {
		try {
			String hql = "from Information where informationClassificationId=?";
			p = super.splitPageQuery(hql, p, id);
			logger.info("根据分级查询信息成功");
			return p;
		} catch (Exception e) {
			logger.error("根据分级查询信息失败");
			return null;
		}

	}

	@Override
	public Information getInformationByInfoId(Integer infoId) {
		try {
			Information i = null;
			i = (Information) super.find("from Information where informationAccount=?", infoId).get(0);
			logger.info("根据信息id查询信息成功");
			return i;

		} catch (Exception e) {
			e.printStackTrace();
			logger.error("根据信息id查询信息失败");
			return null;
		}

	}

	@Override
	public Page<Information> getInfomationBySort(Page p, int id) {
		try {
			String hql = "from Information where informationSortId=?";
			p = super.splitPageQuery(hql, p, id);
			logger.info("根据分级查询信息成功");
			return p;
		} catch (Exception e) {
			logger.error("根据分级查询信息失败");
			return null;
		}
	}

	@Override
	public Page<Information> getInfomationByUserId(InformationQuery inforQuery, Page p, int userId) {
		try {
			String  intputUserString="";
			if (inforQuery.getUserId().equals("%")) {
				intputUserString=" ";
			}else{
				intputUserString=" and (inputPerSonNames like "+"'%,"+inforQuery.getIntputName()+",%'"+" or userId ="+inforQuery.getUserId()+ ") ";

			}
			String[] sourceStr;
			String queryBySouce=" ";
			if (inforQuery.getInformationSource().equals("%")) {
				queryBySouce=" ";
			}else{
				sourceStr=inforQuery.getInformationSource().split(",");
				for (int i = 0; i < sourceStr.length; i++) {
					queryBySouce+="  and informationSourceID like"+" '%,"+sourceStr[i]+",%'  ";
				}
			}//+" "+queryBySouce
			String port;
			if (inforQuery.getSalfPort().equals("%")) {
				port="  ";
			}else{
				port=" and safetyPortId in("+inforQuery.getSalfPort()+")";
			}
			String hql = "from Information  where    createTime BETWEEN ? AND ? and  informationSortId like ? and informationClassificationId like ?  and informationProfile like ? and flowId like ?   and prisonId like ?  and userId=? "+port+" "+queryBySouce+intputUserString+" order by createTime desc";
			if (!inforQuery.getCurFLow().equals("1")) {
				hql = "from Information  where flowId >1  and     createTime BETWEEN ? AND ? and  informationSortId like ? and informationClassificationId like ?  and informationProfile like ? and flowId like ?   and prisonId like ?  and userId=? "+port+" "+queryBySouce+intputUserString+" order by createTime desc";

			}
			p = super.splitPageQuery(hql, p, inforQuery.getStartTimestamp(), inforQuery.getEndTimestamp(),
					inforQuery.getInformationSort(), inforQuery.getInformationLv(),
					 "%" + inforQuery.getKey() + "%",
					inforQuery.getCurFLow(),inforQuery.getStructure(),userId);
			logger.info("根据录入人查询信息成功");
			p=getUserNameByInfoUserId(p);
			return p;
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("根据录入人查询信息失败");
			return null;
		}
	}
	@Override
	public Page<Information> getRateInfomationByQuery(InformationQuery inforQuery, Page p, Integer userId) {
		String  intputUserString="";
		if (inforQuery.getUserId().equals("%")) {
			intputUserString=" ";
		}else{
			intputUserString=" and (inforTable.inputPerSonNames like "+"'%,"+inforQuery.getIntputName()+",%'"+" or inforTable.userId ="+inforQuery.getUserId()+ ") ";

		}
		String[] sourceStr;
		String queryBySouce=" ";
		if (inforQuery.getInformationSource().equals("%")) {
			queryBySouce=" ";
		}else{
			sourceStr=inforQuery.getInformationSource().split(",");
			for (int i = 0; i < sourceStr.length; i++) {
				queryBySouce+="  and inforTable.informationSourceID like"+" '%,"+sourceStr[i]+",%'  ";
			}
		}//+" "+queryBySouce
		String port;
		if (inforQuery.getSalfPort().equals("%")) {
			port="  ";
		}else{
			port=" and inforTable.safetyPortId in("+inforQuery.getSalfPort()+")";
		}
		
		String str = "new Information(inforTable.id, inforTable.informationAccount, inforTable.informationType, inforTable.informationSourceID, inforTable.informationSourceNames, inforTable.inputPersonID, inforTable.inputPerSonNames, inforTable.informationProfile, inforTable.informationConternt, inforTable.mesure, inforTable.standard, inforTable.informationClassificationId, inforTable.informationSortId, inforTable.informationClassificationNames, inforTable.informationSortNames, inforTable.appendix, inforTable.taskCompletion, inforTable.safetyPortId, inforTable.safetyPortNames, inforTable.createTime, inforTable.userId, inforTable.jbpmPdId, inforTable.flowId, inforTable.flowName, inforTable.prisonId)";

			//"SELECT COUNT(oneInfo.id) FROM Information as oneInfo,Informationflow flow  where  flow.lastFlowId=? and flow.informationId=oneInfo.id AND oneInfo.id not in("
					//+"SELECT a.informationId from EvaluationRecord  as a  where a.userId=?
			
		String hql = "select distinct "+str
				+ " FROM Information as inforTable,InformationFlow flow where flow.informationId=inforTable.id and    inforTable.id not in("
					+"SELECT a.informationId from EvaluationRecord  as a  where a.userid=?) and inforTable.createTime BETWEEN ? AND ? and  inforTable.informationSortId like ? and  inforTable.informationClassificationId like ?  and inforTable.informationProfile like ?  and inforTable.informationClassificationId like ?  "
					+"and inforTable.prisonId like ?  "+intputUserString+"  " +port+" "+queryBySouce+ " order By inforTable.createTime desc ";
		String noSelct=" inforTable.id) FROM Information as inforTable,InformationFlow flow  where flow.informationId=inforTable.id and    inforTable.id not in("
				+"SELECT a.informationId from EvaluationRecord  as a  where a.userid=?) and inforTable.createTime BETWEEN ? AND ? and  inforTable.informationSortId like ? and  inforTable.informationClassificationId like ?  and inforTable.informationProfile like ?  and inforTable.informationClassificationId like ?  "
				+"and inforTable.prisonId like ? "+intputUserString+"  " +port+" "+queryBySouce+ " order By inforTable.createTime desc ";

		p = super.splitPageQuerySelect(hql, p,noSelct,userId, inforQuery.getStartTimestamp(), inforQuery.getEndTimestamp(),
						inforQuery.getInformationSort(), inforQuery.getInformationLv(),
						 "%" + inforQuery.getKey() + "%",
						 inforQuery.getInformationType(),inforQuery.getStructure()
						 );
		logger.info("查询信息成功");
		p=getUserNameByInfoUserId(p);
		return p;
		
	}

	@Override
	public Page<Information> getCommentInfomationByQuery(InformationQuery inforQuery, Page p, String wherehql, String arges) {
		try {
			String  intputUserString="";
			if (inforQuery.getUserId().equals("%")) {
				intputUserString=" ";
			}else{
				intputUserString=" and (inforTable.inputPerSonNames like "+"'%,"+inforQuery.getIntputName()+",%'"+" or inforTable.userId ="+inforQuery.getUserId()+ ") ";

			}
			String[] sourceStr;
			String queryBySouce=" ";
			if (inforQuery.getInformationSource().equals("%")) {
				queryBySouce=" ";
			}else{
				sourceStr=inforQuery.getInformationSource().split(",");
				for (int i = 0; i < sourceStr.length; i++) {
					queryBySouce+="  and inforTable.informationSourceID like"+" '%,"+sourceStr[i]+",%'  ";
				}
			}//+" "+queryBySouce
			String port;
			if (inforQuery.getSalfPort().equals("%")) {
				port="  ";
			}else{
				port=" and inforTable.safetyPortId in("+inforQuery.getSalfPort()+") ";
			}
			
			if (arges == null || arges.isEmpty()) {
				//"SELECT COUNT(id) from Information information where (information.flowId<? and information.id not in(SELECT info.id from Information info,CommentRecord record where record.informationId=info.id) or information.flowId=?) AND information.prisonId=?
					String hql = "from Information inforTable where (inforTable.flowId<? and inforTable.id not in(SELECT info.id from Information info,CommentRecord record where record.informationId=info.id) or inforTable.flowId=?) and inforTable.createTime BETWEEN ? AND ? "
							+ "and  inforTable.informationSortId like ? and  inforTable.informationClassificationId like ? and inforTable.informationProfile like ? and inforTable.flowId like ? and inforTable.informationClassificationId like ?  "
							+intputUserString+" and inforTable.prisonId like ? "+ wherehql +port+" "+queryBySouce+ " order By inforTable.createTime desc ";
					p = super.splitPageQuery(hql, p, inforQuery.getStartTimestamp(), inforQuery.getEndTimestamp(),
							inforQuery.getInformationSort(), inforQuery.getInformationLv(),
							 "%" + inforQuery.getKey() + "%",
							inforQuery.getCurFLow(), inforQuery.getInformationType()
							,inforQuery.getStructure() );
					logger.info("查询信息成功");
				
				return p;
			} else {
				String hql = " from Information inforTable where ( (cast(inforTable.flowId as int)<? and inforTable.id not in(SELECT info.id from Information info,CommentRecord record where record.informationId=info.id)) or (cast(inforTable.flowId as int) = ?))   " 
						+ "and inforTable.createTime BETWEEN ? AND ? "
						+ "and  inforTable.informationSortId like ? and  inforTable.informationClassificationId like ?  and inforTable.informationProfile like ?  and inforTable.informationClassificationId like ?  "
						+intputUserString+" and inforTable.prisonId like ? "+ wherehql +port+" "+queryBySouce+ " order By inforTable.createTime desc ";

//						+ wherehql +port+ " order By inforTable.createTime desc ";
						
				p = super.splitPageQuery(hql, p,9,9, inforQuery.getStartTimestamp(), inforQuery.getEndTimestamp(),
						inforQuery.getInformationSort(), inforQuery.getInformationLv(),
						 "%" + inforQuery.getKey() + "%",
						 inforQuery.getInformationType(),inforQuery.getStructure()	,arges);			
				logger.info("查询信息成功");
				p=getUserNameByInfoUserId(p);
				return p;
			}

		} catch (Exception e) {
			e.printStackTrace();
			logger.error("查询信息失败");
			return null;
		}
	}
	
	@Override
	public Page<Information> getInfomationByQuery(InformationQuery inforQuery, Page p, String wherehql, String arges) {
		try {
			String  intputUserString="";
			if (inforQuery.getUserId().equals("%")) {
				intputUserString=" ";
			}else{
				intputUserString=" and (inputPerSonNames like "+"'%,"+inforQuery.getIntputName()+",%'"+" or userId ="+inforQuery.getUserId()+ ") ";

			}
			String[] sourceStr;
			String queryBySouce=" ";
			if (inforQuery.getInformationSource().equals("%")) {
				queryBySouce=" ";
			}else{
				sourceStr=inforQuery.getInformationSource().split(",");
				for (int i = 0; i < sourceStr.length; i++) {
					queryBySouce+="  and informationSourceID like"+" '%,"+sourceStr[i]+",%'  ";
				}
			}//+" "+queryBySouce
			String port;
			if (inforQuery.getSalfPort().equals("%")) {
				port="  ";
			}else{
				port=" and safetyPortId in("+inforQuery.getSalfPort()+")";
			}
			
			if (arges == null || arges.isEmpty()) {
				//"SELECT COUNT(oneInfo.id) FROM Information as oneInfo,Informationflow flow  where  flow.lastFlowId=? and flow.informationId=oneInfo.id AND oneInfo.id not in("
						//+"SELECT a.informationId from EvaluationRecord  as a  where a.userId=?
				
					String hql = "from Information  where createTime BETWEEN ? AND ? and  informationSortId like ? and  informationClassificationId like ?  and informationProfile like ? and flowId like ? and informationClassificationId like ?  "
							+ intputUserString+ "   and prisonId like ? "+ wherehql +port+" "+queryBySouce+ " order By createTime desc ";
					p = super.splitPageQuery(hql, p, inforQuery.getStartTimestamp(), inforQuery.getEndTimestamp(),
							inforQuery.getInformationSort(), inforQuery.getInformationLv(),
							"%" + inforQuery.getKey() + "%",
							inforQuery.getCurFLow(), inforQuery.getInformationType()
							,inforQuery.getStructure() );
					logger.info("查询信息成功");
					p=getUserNameByInfoUserId(p);
				
				return p;
			} else {
				String hql = "from Information  where createTime BETWEEN ? AND ? and  informationSortId like ? and  informationClassificationId like ?  and informationProfile like ? and flowId like ? and informationClassificationId like ?   "
						+intputUserString+ "  and prisonId like ? "+ wherehql +port+" "+queryBySouce+ "  order By createTime desc";
				p = super.splitPageQuery(hql, p, inforQuery.getStartTimestamp(), inforQuery.getEndTimestamp(),
						inforQuery.getInformationSort(), inforQuery.getInformationLv(),
						 "%" + inforQuery.getKey() + "%",
						inforQuery.getCurFLow(), inforQuery.getInformationType(),
						inforQuery.getStructure(), arges);
				logger.info("查询信息成功");
				p=getUserNameByInfoUserId(p);
				return p;
			}

		} catch (Exception e) {
			e.printStackTrace();
			logger.error("查询信息失败");
			return null;
		}
	}
	@Override
	public Page<Information> getInfomationByInfoQuery(InformationQuery inforQuery, Page p, String wherehql, String arges) {
		try {
			String[] sourceStr;
			String queryBySouce=" ";
			if (inforQuery.getInformationSource().equals("%")) {
				queryBySouce=" ";
			}else{
				sourceStr=inforQuery.getInformationSource().split(",");
				for (int i = 0; i < sourceStr.length; i++) {
					queryBySouce+="  and informationSourceID like"+" '%,"+sourceStr[i]+",%'  ";
				}
			}//+" "+queryBySouce
			String port;
			if (inforQuery.getSalfPort().equals("%")) {
				port="  ";
			}else{
				port=" and safetyPortId in("+inforQuery.getSalfPort()+")";
			}
			
			if (arges == null || arges.isEmpty()) {
				String hql = "from Information  where createTime BETWEEN ? AND ? and  informationSortId like ? and  informationClassificationId like ?  and informationProfile like ? and flowId like ? and informationClassificationId like ?  "
						+ wherehql+port+" "+queryBySouce + " order By createTime desc ";
				p = super.splitPageQuery(hql, p, inforQuery.getStartTimestamp(), inforQuery.getEndTimestamp(),
						inforQuery.getInformationSort(), inforQuery.getInformationLv(),
						 "%" + inforQuery.getKey() + "%",
						inforQuery.getCurFLow(), inforQuery.getInformationType()
						 );
				logger.info("查询信息成功");
				p=getUserNameByInfoUserId(p);
				return p;
			} else {
				String hql = "from Information  where createTime BETWEEN ? AND ? and  informationSortId like ? and  informationClassificationId like ? and  and informationProfile like ? and flowId like ? and informationClassificationId like ?  "
						+ wherehql +port+" "+queryBySouce+ "  order By createTime desc";
				p = super.splitPageQuery(hql, p, inforQuery.getStartTimestamp(), inforQuery.getEndTimestamp(),
						inforQuery.getInformationSort(), inforQuery.getInformationLv(),
						 "%" + inforQuery.getKey() + "%",
						inforQuery.getCurFLow(), inforQuery.getInformationType(),
					    arges);
				logger.info("查询信息成功");
				p=getUserNameByInfoUserId(p);
				return p;
			}

		} catch (Exception e) {
			e.printStackTrace();
			logger.error("查询信息失败");
			return null;
		}
	}
	@Override
	public Page<Information> getInfomationByQuery(InformationQuery inforQuery, Page p, int userId) {

		String hql = "select new Information(inforTable.id, inforTable.informationAccount, inforTable.informationType, inforTable.informationSourceID, inforTable.informationSourceNames, inforTable.inputPersonID, inforTable.inputPerSonNames, inforTable.informationProfile, inforTable.informationConternt, inforTable.mesure, inforTable.standard, inforTable.informationClassificationId, inforTable.informationSortId, inforTable.informationClassificationNames, inforTable.informationSortNames, inforTable.appendix, inforTable.taskCompletion, inforTable.safetyPortId, inforTable.safetyPortNames, inforTable.createTime, inforTable.userId, inforTable.jbpmPdId, inforTable.flowId, inforTable.flowName, inforTable.prisonId) from Information inforTable,TaskDispatch taskDisTable,InformationFlow inforFlowTalbe where inforFlowTalbe.informationId=taskDisTable.informationId and inforFlowTalbe.informationId=inforTable.id  inforTable.userId=? or inforFlowTalbe.userId=? or taskDisTable.personLiableId =?  ";
		String noSelct = "";
		p=super.splitPageQuerySlect(hql, p, noSelct, userId, userId, userId);
		p=getUserNameByInfoUserId(p);
		return p;

	}

	@Override
	public Page<TaskInformationView> getUserZeRenInfoList(InformationQuery inforQuery, Page p, int userId, int state) {
		String str;
		String hql;
		String noSelct;
		String comment;
		String[] sourceStr;
		String queryBySouce=" ";
		String  intputUserString="";
		if (inforQuery.getUserId().equals("%")) {
			intputUserString=" ";
		}else{
			intputUserString=" and (inforTable.inputPerSonNames like "+"'%,"+inforQuery.getIntputName()+",%'"+" or inforTable.userId ="+inforQuery.getUserId()+ ") ";

			
		}
		if (inforQuery.getInformationSource().equals("%")) {
			queryBySouce=" ";
		}else{
			sourceStr=inforQuery.getInformationSource().split(",");
			for (int i = 0; i < sourceStr.length; i++) {
				queryBySouce+="  and inforTable.informationSourceID like"+" '%,"+sourceStr[i]+",%'  ";
			}
		}//+" "+queryBySouce
		String port;
		if (inforQuery.getSalfPort().equals("%")) {
			port="  ";
		}else{
			port=" and inforTable.safetyPortId in("+inforQuery.getSalfPort()+")";
		}
		String completeComment;
		str = " new com.yuxi.Entity.TaskInformationView(inforTable.id,inforTable.userId, inforTable.informationAccount, inforTable.informationType,inforTable.safetyPortId,inforTable.informationSourceID,inforTable.informationSourceNames, inforTable.inputPerSonNames, inforTable.informationProfile, inforTable.informationConternt, inforTable.mesure, inforTable.standard, inforTable.informationClassificationId, inforTable.informationClassificationNames, inforTable.informationSortNames, inforTable.safetyPortNames, inforTable.createTime, inforTable.zeRenPerSonNames, inforTable.zeRenTime, taskDisTable.id, taskDisTable.personDispatchName,taskDisTable.remark,taskDisTable.status,taskDisTable.type,inforTable.flowId,inforTable.flowName)";
		if (!inforQuery.getQualityId().equals("%")) {
			comment=",CommentRecord commentTable where commentTable.informationId=inforTable.id and  commentTable.informationQualityId like "+inforQuery.getQualityId()+" and ";
			
		} else{
			comment=" ,CommentRecord commentTable where " ;

		}
		System.out.println(comment);
		if(!inforQuery.getCompleteId().equals("%")){
			 completeComment="  commentTable.taskCompletionId like "+inforQuery.getCompleteId()+" and ";
		}else{
			completeComment=" " ;
		}
		if (inforQuery.getInformationJudge().equals("%")) {
			
					hql = "select distinct " + str
					+ " from Information inforTable,TaskDispatch taskDisTable  "+comment+completeComment+" inforTable.id=taskDisTable.informationId and taskDisTable.status=? and taskDisTable.personLiableId=? and taskDisTable.taskTime BETWEEN ? AND ? "
					+ "and  inforTable.informationSortId like ?  and inforTable.informationProfile like ?  and inforTable.informationClassificationId like ?  "
					+ intputUserString+" and taskDisTable.personDispatchName like ? and inforTable.prisonId like ? "+port+" "+queryBySouce+" order by inforTable.createTime desc";
			noSelct = " inforTable.id) from Information as inforTable,TaskDispatch as taskDisTable "+comment+completeComment+"  inforTable.id=taskDisTable.informationId and  taskDisTable.status=?  and taskDisTable.personLiableId=?  "
					+ "and taskDisTable.taskTime BETWEEN ? AND ? and "
					+ " inforTable.informationSortId like ?  and inforTable.informationProfile like ?  and inforTable.informationClassificationId like ?  "
					+ intputUserString+" and taskDisTable.personDispatchName like ? and inforTable.prisonId like ? "+port+" "+queryBySouce+"   order by inforTable.createTime desc";
			p = super.splitPageQuerySelect(hql, p, noSelct, state, userId, inforQuery.getStartFinishTime(),
					inforQuery.getEndFinishTime(), inforQuery.getInformationSort(),
					 "%" + inforQuery.getKey() + "%",
					 inforQuery.getInformationLv(),inforQuery.getFinisPerson(),inforQuery.getStructure());

		}else if (inforQuery.getInformationJudge().equals("1")) {
			
			hql = "select distinct " + str
					+ " from Information inforTable,TaskDispatch taskDisTable "+comment+completeComment+"inforTable.id=taskDisTable.informationId and taskDisTable.status=? and taskDisTable.personLiableId=? and taskDisTable.taskTime = ? "
					+ "and  inforTable.informationSortId like ?  and inforTable.informationProfile like ?  and inforTable.informationClassificationId like ?  "
					+ intputUserString+" and taskDisTable.personDispatchName like ? and inforTable.prisonId like ?  "+port+" "+queryBySouce+" order by inforTable.createTime desc";
			noSelct = " inforTable.id) from Information as inforTable,TaskDispatch as taskDisTable "+comment+completeComment+" inforTable.id=taskDisTable.informationId and  taskDisTable.status=?  and taskDisTable.personLiableId=?  "
					+ "and taskDisTable.taskTime = ? and "
					+ " inforTable.informationSortId like ?  and inforTable.informationProfile like ?  and inforTable.informationClassificationId like ?   "
					+ intputUserString+" and taskDisTable.personDispatchName like ? and inforTable.prisonId like ?     "+port+" "+queryBySouce+" order by inforTable.createTime desc";
			p = super.splitPageQuerySelect(hql, p, noSelct, state, userId, 
					Long.valueOf("3502800000000"), inforQuery.getInformationSort(),
					 "%" + inforQuery.getKey() + "%",
					 inforQuery.getInformationLv(),inforQuery.getFinisPerson(),inforQuery.getStructure());

		}else {
			
			hql = "select distinct " + str
					+ " from Information inforTable,TaskDispatch taskDisTable "+comment+completeComment+" inforTable.id=taskDisTable.informationId and taskDisTable.status=? and taskDisTable.personLiableId=? and taskDisTable.taskTime BETWEEN ? AND ? and taskDisTable.taskTime !=  ? "
					+ "and  inforTable.informationSortId like ?  and inforTable.informationProfile like ?  and inforTable.informationClassificationId like ?   "
					+ intputUserString+" and taskDisTable.personDispatchName like ? and inforTable.prisonId like ?  "+port+" "+queryBySouce+" order by inforTable.createTime desc";
			noSelct = " inforTable.id) from Information as inforTable,TaskDispatch as taskDisTable "+comment+completeComment+" inforTable.id=taskDisTable.informationId and  taskDisTable.status=?  and taskDisTable.personLiableId=?  "
					+ "and taskDisTable.taskTime BETWEEN ? AND ? and taskDisTable.taskTime != ? and "
					+ " inforTable.informationSortId like ?  and inforTable.informationProfile like ?  and inforTable.informationClassificationId like ?  "
					+ intputUserString+"and taskDisTable.personDispatchName like ? and inforTable.prisonId like ?  "+port+" "+queryBySouce+" order by inforTable.createTime desc";
			p = super.splitPageQuerySelect(hql, p, noSelct, state, userId, inforQuery.getStartFinishTime(),
					inforQuery.getEndFinishTime(), Long.valueOf("3502800000000"),inforQuery.getInformationSort(),
					 "%" + inforQuery.getKey() + "%",
					 inforQuery.getInformationLv(),inforQuery.getFinisPerson(),inforQuery.getStructure());

		}
		p=getUserNameByTaskViewUserId(p);
		return p;
	}
//待查点评
	@Override
	public Page<Information> getAllCommentInformation(InformationQuery inforQuery, Page p,int userId) {
		String inputName="";
		String finsihName="";
		String str;
		String hql;
		String noSelct;
		String port;//u.getUserId(),"%,"+u.getUserId()+",%","%,"+u.getUserId()+",%"
		String people=" and (inforTable.userId ="+Integer.toString(userId)+" or inforTable.zeRenPersonId like "+"'%,"+Integer.toString(userId)+",%'"+"  or inforTable.inputPersonID like "+"'%,"+Integer.toString(userId)+",%'"+")"+"  ";
		if (inforQuery.getSalfPort().equals("%")) {
			port="  ";
		}else{
			port=" and safetyPortId in("+inforQuery.getSalfPort()+")";
		}
		String[] sourceStr;
		String queryBySouce=" ";
		if (inforQuery.getInformationSource().equals("%")) {
			queryBySouce=" ";
		}else{
			sourceStr=inforQuery.getInformationSource().split(",");
			for (int i = 0; i < sourceStr.length; i++) {
				queryBySouce+="  and inforTable.informationSourceID like"+" '%,"+sourceStr[i]+",%'  ";
			}
		}//+" "+queryBySouce
		
//		flowId=flowId+1;
		str = "new Information(inforTable.id, inforTable.informationAccount, inforTable.informationType, inforTable.informationSourceID, inforTable.informationSourceNames, inforTable.inputPersonID, inforTable.inputPerSonNames, inforTable.informationProfile, inforTable.informationConternt, inforTable.mesure, inforTable.standard, inforTable.informationClassificationId, inforTable.informationSortId, inforTable.informationClassificationNames, inforTable.informationSortNames, inforTable.appendix, inforTable.taskCompletion, inforTable.safetyPortId, inforTable.safetyPortNames, inforTable.createTime, inforTable.userId, inforTable.jbpmPdId, inforTable.flowId, inforTable.flowName, inforTable.prisonId)";
		
		if (inforQuery.getIntputName().equals("%")) {
			inputName="%";
		}else{
			inputName="%,"+inforQuery.getIntputName()+",%";
		}
		if (inforQuery.getFinisPerson().equals("%")) {
			finsihName="%";
		}else{
			finsihName="%,"+inforQuery.getFinisPerson()+",%";
		}
		if (inforQuery.getInformationJudge().equals("1")) {
			hql = "select distinct  " + str
					+ " FROM Information as inforTable,CommentRecord record,InformationFlow infoFLowTable where infoFLowTable.informationId=inforTable.id and inforTable.id=record.informationId AND inforTable.id not in("
					+"SELECT b.informationId from CommentRecord  as a,CommentRecordBrowse as b where a.informationId=b.informationId and b.userId=?)"
					+"and inforTable.createTime BETWEEN ? AND ? and  inforTable.informationSortId like ? and inforTable.informationClassificationId like ?  and inforTable.informationProfile like ?  "
					+" and inforTable.inputPerSonNames like ? and inforTable.zeRenPerSonNames like ? and inforTable.prisonId like ? and infoFLowTable.createTime BETWEEN ? AND ? "+port+" "+queryBySouce+people+" order by  inforTable.createTime desc ";
			noSelct =" inforTable.id) FROM Information as inforTable,CommentRecord record,InformationFlow infoFLowTable where infoFLowTable.informationId=inforTable.id and inforTable.id=record.informationId AND inforTable.id not in("
					+"SELECT b.informationId from CommentRecord  as a,CommentRecordBrowse as b where a.informationId=b.informationId and b.userId=?)"
					+"and inforTable.createTime BETWEEN ? AND ? and  inforTable.informationSortId like ? and inforTable.informationClassificationId like ?  and inforTable.informationProfile like ?  "
					+" and inforTable.inputPerSonNames like ? and inforTable.zeRenPerSonNames like ? and inforTable.prisonId like ? and infoFLowTable.createTime BETWEEN ? AND ? "+port+" "+queryBySouce+people+"  order by  inforTable.createTime desc ";

			p = super.splitPageQuerySelect(hql, p, noSelct,userId,inforQuery.getStartTimestamp(),
					inforQuery.getEndTimestamp(), inforQuery.getInformationSort(), inforQuery.getInformationLv(),
					 "%" + inforQuery.getKey() + "%",inputName,finsihName,inforQuery.getStructure(),inforQuery.getStartCommitTime(),inforQuery.getEndCommitTime());
					
		}else if(inforQuery.getInformationJudge().equals("2")) {
			System.out.println("kkkkkkkkkkkkkkkkk");
			hql = "select distinct  " + str
					+ "  FROM Information as inforTable,CommentRecordBrowse record,InformationFlow infoFLowTable where infoFLowTable.informationId=inforTable.id and inforTable.id=record.informationId AND record.userId=? "
					+"and inforTable.createTime BETWEEN ? AND ? and  inforTable.informationSortId like ? and inforTable.informationClassificationId like ?  and inforTable.informationProfile like ?  "
					+" and inforTable.inputPerSonNames like ? and inforTable.zeRenPerSonNames like ? and inforTable.prisonId like ? and infoFLowTable.createTime BETWEEN ? AND ?  "+port+" "+queryBySouce+" order by   inforTable.createTime  desc ";
			noSelct =" inforTable.id) FROM Information as inforTable,CommentRecordBrowse record,InformationFlow infoFLowTable where infoFLowTable.informationId=inforTable.id and inforTable.id=record.informationId AND record.userId=? "

					+"and inforTable.createTime BETWEEN ? AND ? and  inforTable.informationSortId like ? and inforTable.informationClassificationId like ?  and inforTable.informationProfile like ?  "
					+" and inforTable.inputPerSonNames like ? and inforTable.zeRenPerSonNames like ? and inforTable.prisonId like ? and infoFLowTable.createTime BETWEEN ? AND ? "+port+" "+queryBySouce+" order by    inforTable.createTime  desc ";

			p = super.splitPageQuerySelect(hql, p, noSelct,userId,inforQuery.getStartTimestamp(),
					inforQuery.getEndTimestamp(), inforQuery.getInformationSort(), inforQuery.getInformationLv(),
					 "%" + inforQuery.getKey() + "%",inputName,finsihName,inforQuery.getStructure(),inforQuery.getStartCommitTime(),inforQuery.getEndCommitTime());
					
		}
				
		p=getUserNameByInfoUserId(p);
		return p;
	}

	@Override
	public Page<Information> getAllEvaluationInformation(InformationQuery inforQuery, Page p,Integer userId) {
		String inputName="";
		String finsihName="";
		String str;
		String hql;
		String noSelct;
		String[] sourceStr;
		String queryBySouce=" ";
		if (inforQuery.getInformationSource().equals("%")) {
			queryBySouce=" ";
		}else{
			sourceStr=inforQuery.getInformationSource().split(",");
			for (int i = 0; i < sourceStr.length; i++) {
				queryBySouce+="  and inforTable.informationSourceID like"+" '%,"+sourceStr[i]+",%'  ";
			}
		}//+" "+queryBySouce
		String port;
		if (inforQuery.getSalfPort().equals("%")) {
			port="  ";
		}else{
			port=" and safetyPortId in("+inforQuery.getSalfPort()+")";
		}
//		flowId=flowId+1;
		str = "new Information(inforTable.id, inforTable.informationAccount, inforTable.informationType, inforTable.informationSourceID, inforTable.informationSourceNames, inforTable.inputPersonID, inforTable.inputPerSonNames, inforTable.informationProfile, inforTable.informationConternt, inforTable.mesure, inforTable.standard, inforTable.informationClassificationId, inforTable.informationSortId, inforTable.informationClassificationNames, inforTable.informationSortNames, inforTable.appendix, inforTable.taskCompletion, inforTable.safetyPortId, inforTable.safetyPortNames, inforTable.createTime, inforTable.userId, inforTable.jbpmPdId, inforTable.flowId, inforTable.flowName, inforTable.prisonId)";
		
		if (inforQuery.getIntputName().equals("%")) {
			inputName="%";
		}else{
			inputName="%,"+inforQuery.getIntputName()+",%";
		}
		if (inforQuery.getFinisPerson().equals("%")) {
			finsihName="%";
		}else{
			finsihName="%,"+inforQuery.getFinisPerson()+",%";
		}
		//SELECT  DISTINCT oneInfo.id FROM Information as oneInfo,EvaluationRecordBrowse record where oneInfo.id=record.informationId AND record.userId=? and record.isLook=? GROUP BY oneInfo.id
		if (inforQuery.getInformationJudge().equals("1")) {
			hql = "select DISTINCT " + str
					+"  from Information inforTable,EvaluationRecordBrowse record where inforTable.id=record.informationId and record.userId like ? and record.isLook like ? "
					+" and inforTable.createTime BETWEEN ? AND ? and  inforTable.informationSortId like ? and inforTable.informationClassificationId like ?  and inforTable.informationProfile like ?  "
					+" and inforTable.inputPerSonNames like ? and inforTable.zeRenPerSonNames like ? and inforTable.prisonId like ?  "+port+" "+queryBySouce+"  ";

			noSelct =" inforTable.id) from Information  inforTable,EvaluationRecordBrowse record where inforTable.id=record.informationId and record.userId like ? and record.isLook like ? "
					+" and inforTable.createTime BETWEEN ? AND ? and  inforTable.informationSortId like ? and inforTable.informationClassificationId like ?  and inforTable.informationProfile like ?  "
					+" and inforTable.inputPerSonNames like ? and inforTable.zeRenPerSonNames like ? and inforTable.prisonId like ?  "+port+" "+queryBySouce+"   ";

			p = super.splitPageQuerySelect(hql, p, noSelct,userId,false,inforQuery.getStartTimestamp(),
					inforQuery.getEndTimestamp(), inforQuery.getInformationSort(), inforQuery.getInformationLv(),
					 "%" + inforQuery.getKey() + "%",inputName,finsihName,inforQuery.getStructure());
				
		}else if (inforQuery.getInformationJudge().equals("2")){
			hql = "select DISTINCT  " + str
					+"  from Information inforTable,EvaluationRecordBrowse record where inforTable.id=record.informationId and record.userId like ? and record.isLook like ? "
					+" and inforTable.createTime BETWEEN ? AND ? and  inforTable.informationSortId like ? and inforTable.informationClassificationId like ?  and inforTable.informationProfile like ?  "
					+" and inforTable.inputPerSonNames like ? and inforTable.zeRenPerSonNames like ? and inforTable.prisonId like ? "+port+" "+queryBySouce+" order by inforTable.createTime  desc ";

			noSelct =" inforTable.id) from Information  inforTable,EvaluationRecordBrowse record where inforTable.id=record.informationId and record.userId like ? and record.isLook like ? "
					+" and inforTable.createTime BETWEEN ? AND ? and  inforTable.informationSortId like ? and inforTable.informationClassificationId like ? and inforTable.informationProfile like ?  "
					+" and inforTable.inputPerSonNames like ? and inforTable.zeRenPerSonNames like ? and inforTable.prisonId like ? "+port+" "+queryBySouce+"  order by inforTable.createTime  desc ";

			p = super.splitPageQuerySelect(hql, p, noSelct,userId,true,inforQuery.getStartTimestamp(),
					inforQuery.getEndTimestamp(), inforQuery.getInformationSort(), inforQuery.getInformationLv(),
					 "%" + inforQuery.getKey() + "%",inputName,finsihName,inforQuery.getStructure());
				
		}
		p=getUserNameByInfoUserId(p);
		return p;
	};
	
	
	@Override
	public Page<Information> getInformationAlreadyDoByFLow(InformationQuery inforQuery, int flowId, Page p,
			int userId,List<InformationPort> ports) {
		String userString="  ";
//		if (flowId==2) {
//			for (int i = 0; i < ports.size(); i++) {
//				if (ports.get(i).getPortName().equals("监管安全")||ports.get(i).getPortName().equals("行政后勤")||ports.get(i).getPortName().equals("生产安全")) {
//					userString="  ";
//					break;
//				}
//			}
//		}
		String  intputUserString="";
		if (inforQuery.getUserId().equals("%")) {
			intputUserString=" ";
		}else{
			intputUserString=" and (inforTable.inputPerSonNames like "+"'%,"+inforQuery.getIntputName()+",%'"+" or inforTable.userId ="+inforQuery.getUserId()+ ") ";
		}
		
		String inputName="";
		String finsihName="";
		String str;
		String hql;
		String noSelct;
		String port;
		String[] sourceStr;
		String queryBySouce=" ";
		if (inforQuery.getInformationSource().equals("%")) {
			queryBySouce=" ";
		}else{
			sourceStr=inforQuery.getInformationSource().split(",");
			for (int i = 0; i < sourceStr.length; i++) {
				queryBySouce+="  and inforTable.informationSourceID like"+" '%,"+sourceStr[i]+",%'  ";
			}
		}//+" "+queryBySouce
		
		
		if (inforQuery.getSalfPort().equals("%")) {
			port="  ";
		}else{
			port=" and safetyPortId in("+inforQuery.getSalfPort()+")";
		}
//		flowId=flowId+1;
		str = "new Information(inforTable.id, inforTable.informationAccount, inforTable.informationType, inforTable.informationSourceID, inforTable.informationSourceNames, inforTable.inputPersonID, inforTable.inputPerSonNames, inforTable.informationProfile, inforTable.informationConternt, inforTable.mesure, inforTable.standard, inforTable.informationClassificationId, inforTable.informationSortId, inforTable.informationClassificationNames, inforTable.informationSortNames, inforTable.appendix, inforTable.taskCompletion, inforTable.safetyPortId, inforTable.safetyPortNames, inforTable.createTime, inforTable.userId, inforTable.jbpmPdId, inforTable.flowId, inforTable.flowName, inforTable.prisonId)";
		
		
		if (inforQuery.getFinisPerson().equals("%")) {
			finsihName="%";
		}else{
			finsihName="%,"+inforQuery.getFinisPerson()+",%";
		}
		if(inforQuery.getQualityId().equals("%")||inforQuery.getCompleteId().equals("%")){
			
		}
		if(inforQuery.getInformationJudge().equals("%")){
			
			if (!inforQuery.getQualityId().equals("%")||!inforQuery.getCompleteId().equals("%")) {
				hql = "select distinct " + str
						+ "from Information inforTable,InformationFlow infoFLowTable,CommentRecord commentTable  where commentTable.informationId=inforTable.id and  infoFLowTable.informationId=inforTable.id and infoFLowTable.lastFlowId=? "+userString+" and inforTable.createTime BETWEEN ? AND ? and  inforTable.informationSortId like ? and inforTable.informationClassificationId like ?  and inforTable.informationProfile like ? and inforTable.flowId like ? and inforTable.informationClassificationId like ?"
						+ intputUserString+"  and inforTable.zeRenPerSonNames like ? and inforTable.prisonId like ? and infoFLowTable.createTime BETWEEN ? AND ? and commentTable.informationQualityId like ? and commentTable.taskCompletionId like ?  "
						+ " "+port+" "+queryBySouce+"  order by infoFLowTable.createTime desc";
				noSelct ="from Information inforTable,InformationFlow infoFLowTable, CommentRecord commentTable where  commentTable.informationId=inforTable.id and infoFLowTable.informationId=inforTable.id and infoFLowTable.lastFlowId=? "+userString+" and inforTable.createTime BETWEEN ? AND ? and  inforTable.informationSortId like ? and inforTable.informationClassificationId like ?  and inforTable.informationProfile like ? and inforTable.flowId like ? and inforTable.informationClassificationId like ? "
						+ intputUserString+" and inforTable.zeRenPerSonNames like ? and inforTable.prisonId like ? and infoFLowTable.createTime  BETWEEN ? AND ?  and commentTable.informationQualityId like ? and commentTable.taskCompletionId like ?"
						+ "  "+port+" "+queryBySouce+"   order by infoFLowTable.createTime desc";
				p = super.splitPageQuerySlect(hql, p, noSelct, flowId ,  inforQuery.getStartTimestamp(),
						inforQuery.getEndTimestamp(), inforQuery.getInformationSort(), inforQuery.getInformationLv(),
						 "%" + inforQuery.getKey() + "%",
						inforQuery.getCurFLow(), inforQuery.getInformationType(),finsihName,inforQuery.getStructure(),inforQuery.getStartCommitTime(),inforQuery.getEndCommitTime(),(inforQuery.getQualityId()),(inforQuery.getCompleteId()));
				
			}else {
				
				hql = "select distinct " + str
						+ "from Information inforTable,InformationFlow infoFLowTable  where   infoFLowTable.informationId=inforTable.id and infoFLowTable.lastFlowId=? "+userString+" and inforTable.createTime BETWEEN ? AND ? and  inforTable.informationSortId like ? and inforTable.informationClassificationId like ?  and inforTable.informationProfile like ? and inforTable.flowId like ? and inforTable.informationClassificationId like ?"
						+ intputUserString+" and inforTable.zeRenPerSonNames like ? and inforTable.prisonId like ? and infoFLowTable.createTime BETWEEN ? AND ?    "
						+ " "+port+" "+queryBySouce+"  order by inforTable.createTime  desc ";
				noSelct ="from Information inforTable,InformationFlow infoFLowTable where    infoFLowTable.informationId=inforTable.id and infoFLowTable.lastFlowId=? "+userString+" and inforTable.createTime BETWEEN ? AND ? and  inforTable.informationSortId like ? and inforTable.informationClassificationId like ?  and inforTable.informationProfile like ? and inforTable.flowId like ? and inforTable.informationClassificationId like ? "
						+intputUserString+" and inforTable.zeRenPerSonNames like ? and inforTable.prisonId like ? and infoFLowTable.createTime  BETWEEN ? AND ?   "
						+ " "+port+" "+queryBySouce+"   order by inforTable.createTime  desc";
				p = super.splitPageQuerySlect(hql, p, noSelct, flowId ,  inforQuery.getStartTimestamp(),
						inforQuery.getEndTimestamp(), inforQuery.getInformationSort(), inforQuery.getInformationLv(),
						 "%" + inforQuery.getKey() + "%",
						inforQuery.getCurFLow(), inforQuery.getInformationType(),finsihName,inforQuery.getStructure(),inforQuery.getStartCommitTime(),inforQuery.getEndCommitTime());
				
			}
		}else if (inforQuery.getInformationJudge().equals("1")) {
				
				hql = "select distinct " + str
						+ "from Information inforTable,InformationFlow infoFLowTable,CommentRecord commentTable,EvaluationRecord evaluationTable  where evaluationTable.informationId=inforTable.id and commentTable.informationId=inforTable.id and  infoFLowTable.informationId=inforTable.id and infoFLowTable.lastFlowId=? "+userString+" and inforTable.createTime BETWEEN ? AND ?  and  inforTable.informationSortId like ? and inforTable.informationClassificationId like ?  and inforTable.informationProfile like ? and inforTable.flowId like ? and inforTable.informationClassificationId like ?"
						+ intputUserString+" and inforTable.zeRenPerSonNames like ? and inforTable.prisonId like ? and infoFLowTable.createTime BETWEEN ? AND ? and commentTable.informationQualityId like ? and commentTable.taskCompletionId like ?  "
						+ " "+port+" "+queryBySouce+" order by inforTable.createTime  desc";
				noSelct ="from Information inforTable,InformationFlow infoFLowTable, CommentRecord commentTable,EvaluationRecord evaluationTable  where evaluationTable.informationId=inforTable.id and  commentTable.informationId=inforTable.id and infoFLowTable.informationId=inforTable.id and infoFLowTable.lastFlowId=? "+userString+" and inforTable.createTime BETWEEN ? AND ? and  inforTable.informationSortId like ? and inforTable.informationClassificationId like ?  and inforTable.informationProfile like ? and inforTable.flowId like ? and inforTable.informationClassificationId like ? "
						+ intputUserString+" and inforTable.zeRenPerSonNames like ? and inforTable.prisonId like ? and infoFLowTable.createTime  BETWEEN ? AND ?  and commentTable.informationQualityId like ? and commentTable.taskCompletionId like ?"
						+ " "+port+" "+queryBySouce+"   order by inforTable.createTime  desc";
				p = super.splitPageQuerySlect(hql, p, noSelct, flowId ,  inforQuery.getStartTimestamp(),
						inforQuery.getEndTimestamp(), inforQuery.getInformationSort(), inforQuery.getInformationLv(),
						 "%" + inforQuery.getKey() + "%",
						inforQuery.getCurFLow(), inforQuery.getInformationType(),finsihName,inforQuery.getStructure(),inforQuery.getStartCommitTime(),inforQuery.getEndCommitTime(),(inforQuery.getQualityId()),(inforQuery.getCompleteId()));
				
			
		}else{
			if (!inforQuery.getQualityId().equals("%")||!inforQuery.getCompleteId().equals("%")) {
				
				hql = "select distinct " + str
						+ "from Information inforTable,InformationFlow infoFLowTable,CommentRecord commentTable,EvaluationRecord evaluationTable  where  evaluationTable.informationId!=inforTable.id and commentTable.informationId=inforTable.id and  infoFLowTable.informationId=inforTable.id and infoFLowTable.flowId<=10 and infoFLowTable.lastFlowId=? "+userString+" and inforTable.createTime BETWEEN ? AND ? and  inforTable.informationSortId like ? and inforTable.informationClassificationId like ?  and inforTable.informationProfile like ? and inforTable.flowId like ? and inforTable.informationClassificationId like ?"
						+ intputUserString+" and inforTable.zeRenPerSonNames like ? and inforTable.prisonId like ? and infoFLowTable.createTime BETWEEN ? AND ? and commentTable.informationQualityId like ? and commentTable.taskCompletionId like ?  "
						+ " "+port+" "+queryBySouce+" order by inforTable.createTime desc";
				noSelct ="from Information inforTable,InformationFlow infoFLowTable, CommentRecord commentTable,EvaluationRecord evaluationTable  where  evaluationTable.informationId!=inforTable.id and  commentTable.informationId=inforTable.id and infoFLowTable.informationId=inforTable.id and infoFLowTable.flowId<=10 and infoFLowTable.lastFlowId=? "+userString+" and inforTable.createTime BETWEEN ? AND ? and  inforTable.informationSortId like ? and inforTable.informationClassificationId like ?  and inforTable.informationProfile like ? and inforTable.flowId like ? and inforTable.informationClassificationId like ? "
						+ intputUserString+" and inforTable.zeRenPerSonNames like ? and inforTable.prisonId like ? and infoFLowTable.createTime  BETWEEN ? AND ?  and commentTable.informationQualityId like ? and commentTable.taskCompletionId like ?"
						+ " "+port+" "+queryBySouce+"   order by inforTable.createTime desc";
				p = super.splitPageQuerySlect(hql, p, noSelct, flowId ,  inforQuery.getStartTimestamp(),
						inforQuery.getEndTimestamp(), inforQuery.getInformationSort(), inforQuery.getInformationLv(),
						 "%" + inforQuery.getKey() + "%",
						inforQuery.getCurFLow(), inforQuery.getInformationType(),finsihName,inforQuery.getStructure(),inforQuery.getStartCommitTime(),inforQuery.getEndCommitTime(),(inforQuery.getQualityId()),(inforQuery.getCompleteId()));
			}else{
				
				hql = "select distinct " + str
						+ "from Information inforTable,InformationFlow infoFLowTable  where    infoFLowTable.informationId=inforTable.id and inforTable.flowId<=10 and infoFLowTable.lastFlowId=? "+userString+" and inforTable.createTime BETWEEN ? AND ? and  inforTable.informationSortId like ? and inforTable.informationClassificationId like ?  and inforTable.informationProfile like ? and inforTable.flowId like ? and inforTable.informationClassificationId like ?"
						+ intputUserString+" and inforTable.zeRenPerSonNames like ? and inforTable.prisonId like ? and infoFLowTable.createTime BETWEEN ? AND ?   "
						+ ""+port+" "+queryBySouce+"  order by inforTable.createTime desc";
				noSelct ="from Information inforTable,InformationFlow infoFLowTable   where   infoFLowTable.informationId=inforTable.id and inforTable.flowId<=10 and infoFLowTable.lastFlowId=? "+userString+" and inforTable.createTime BETWEEN ? AND ? and  inforTable.informationSortId like ? and inforTable.informationClassificationId like ?  and inforTable.informationProfile like ? and inforTable.flowId like ? and inforTable.informationClassificationId like ? "
						+intputUserString+" and inforTable.zeRenPerSonNames like ? and inforTable.prisonId like ? and infoFLowTable.createTime  BETWEEN ? AND ?  "
						+ " "+port+" "+queryBySouce+"   order by inforTable.createTime desc";
				p = super.splitPageQuerySlect(hql, p, noSelct, flowId , inforQuery.getStartTimestamp(),
						inforQuery.getEndTimestamp(), inforQuery.getInformationSort(), inforQuery.getInformationLv(),
						"%" + inforQuery.getKey() + "%",
						inforQuery.getCurFLow(), inforQuery.getInformationType(),finsihName,inforQuery.getStructure(),inforQuery.getStartCommitTime(),inforQuery.getEndCommitTime());

			}
		}
		p=getUserNameByInfoUserId(p);
		return p;
	}
	@Override
	public Page<Information> getAllInformation(InformationQuery inforQuery,   Page p,PrisonStructure pStructure
			) {
		String  intputUserString="";
		if (inforQuery.getUserId().equals("%")) {
			intputUserString=" ";
		}else{
			intputUserString=" and (inforTable.inputPerSonNames like "+"'%,"+inforQuery.getIntputName()+",%'"+" or inforTable.userId ="+inforQuery.getUserId()+ ") ";

		}
		String pString=" ";
		if (pStructure.getValue().equals("Prison")) {
			pString=" ";
		}else{
			pString=" and inforTable.prisonId =  " +pStructure.getId()+"  ";
		}
		String inputName="";
		String finsihName="";
		String str;
		String hql;
		String noSelct;
		String port;
		String[] sourceStr;
		String queryBySouce=" ";
		
		
		if (inforQuery.getInformationSource().equals("%")) {
			queryBySouce=" ";
		}else{
			sourceStr=inforQuery.getInformationSource().split(",");
			for (int i = 0; i < sourceStr.length; i++) {
				queryBySouce+="  and inforTable.informationSourceID like"+" '%,"+sourceStr[i]+",%'  ";
			}
		}//+" "+queryBySouce//"%," + inforQuery.getInformationSource() + ",%",
		if (inforQuery.getSalfPort().equals("%")) {
			port="  ";
		}else{
			port=" and inforTable.safetyPortId in("+inforQuery.getSalfPort()+")";
		}

		str = "new Information(inforTable.id, inforTable.informationAccount, inforTable.informationType, inforTable.informationSourceID, inforTable.informationSourceNames, inforTable.inputPersonID, inforTable.inputPerSonNames, inforTable.informationProfile, inforTable.informationConternt, inforTable.mesure, inforTable.standard, inforTable.informationClassificationId, inforTable.informationSortId, inforTable.informationClassificationNames, inforTable.informationSortNames, inforTable.appendix, inforTable.taskCompletion, inforTable.safetyPortId, inforTable.safetyPortNames, inforTable.createTime, inforTable.userId, inforTable.jbpmPdId, inforTable.flowId, inforTable.flowName, inforTable.prisonId)";
		
		
		if (inforQuery.getFinisPerson().equals("%")) {
			finsihName="%";
		}else{
			finsihName="%,"+inforQuery.getFinisPerson()+",%";
		}
		if(inforQuery.getQualityId().equals("%")||inforQuery.getCompleteId().equals("%")){
			
		}
		String subTime="  ";
		//(( infoFLowTable.endTime BETWEEN ? AND ? and infoFLowTable.flowId =?) or ( infoFLowTable.endTime BETWEEN ? AND ? and infoFLowTable.flowId =? ) or( infoFLowTable.endTime BETWEEN ? AND ? and infoFLowTable.flowId =? ) or( infoFLowTable.endTime BETWEEN ? AND ? and infoFLowTable.flowId =?   ) or (inforTable.flowId <= 1) or (inforTable.flowId >= 6) )
		if(inforQuery.getFirstStartTime()!=0&& inforQuery.getFirstStartTime()!=0 ){
			subTime+=" and ( infoFLowTable.endTime BETWEEN "+inforQuery.getFirstStartTime()+" AND "+inforQuery.getFirstEndTime()+" and infoFLowTable.flowId ="+ConfigStatic.FLOWTABLE.get("FirstCheck")+") ";
		}
		if(inforQuery.getReCheckStartTime()!=0&& inforQuery.getReCheckEndTime()!=0 ){
			subTime+=" and ( infoFLowTable.endTime BETWEEN "+inforQuery.getReCheckStartTime()+" AND "+inforQuery.getReCheckEndTime()+" and infoFLowTable.flowId ="+ConfigStatic.FLOWTABLE.get("ReCheck")+")  ";
		}
		if(inforQuery.getCheckStartTime()!=0&& inforQuery.getCheckEndTime()!=0 ){
			subTime+=" and ( infoFLowTable.endTime BETWEEN "+inforQuery.getCheckStartTime()+" AND "+inforQuery.getCheckEndTime()+" and infoFLowTable.flowId ="+ConfigStatic.FLOWTABLE.get("ReCheck")+")  ";
		}
		if(inforQuery.getResearchStartTime()!=0&& inforQuery.getResearchEndTime()!=0 ){
			subTime+=" and ( infoFLowTable.endTime BETWEEN "+inforQuery.getResearchStartTime()+" AND "+inforQuery.getResearchEndTime()+" and infoFLowTable.flowId ="+ConfigStatic.FLOWTABLE.get("ReCheck")+")  ";
		}
		
		if(inforQuery.getInformationJudge().equals("%")){
			if (!inforQuery.getQualityId().equals("%")||!inforQuery.getCompleteId().equals("%")) {
				hql = "select DISTINCT  " + str
						+ "from Information inforTable,InformationFlow infoFLowTable,CommentRecord commentTable  where commentTable.informationId=inforTable.id and  infoFLowTable.informationId=inforTable.id "+subTime+"    and infoFLowTable.isEnable=1   and inforTable.createTime BETWEEN ? AND ? and  inforTable.informationSortId like ? and inforTable.informationClassificationId like ?  and inforTable.informationProfile like ? and inforTable.flowId like ? and inforTable.informationClassificationId like ?"
						+ intputUserString+" and inforTable.zeRenPerSonNames like ? and inforTable.prisonId like ? and infoFLowTable.createTime BETWEEN ? AND ? and commentTable.informationQualityId like ? and commentTable.taskCompletionId like ?  "
						+ "  "+port+" "+queryBySouce+pString+" order by inforTable.createTime desc group by inforTable.id";
				noSelct =" inforTable.id) from Information inforTable,InformationFlow infoFLowTable, CommentRecord commentTable where  commentTable.informationId=inforTable.id and infoFLowTable.informationId=inforTable.id "+subTime+"   and   infoFLowTable.isEnable=1  and inforTable.createTime BETWEEN ? AND ? and  inforTable.informationSortId like ? and inforTable.informationClassificationId like ? and inforTable.informationProfile like ? and inforTable.flowId like ? and inforTable.informationClassificationId like ? "
						+ intputUserString+"  and inforTable.zeRenPerSonNames like ? and inforTable.prisonId like ? and infoFLowTable.createTime  BETWEEN ? AND ?  and commentTable.informationQualityId like ? and commentTable.taskCompletionId like ?"
						+ " "+port+" "+queryBySouce+pString+"   order by inforTable.createTime desc group by inforTable.id";
				p = super.splitPageQuerySelect(hql, p, noSelct,
						 inforQuery.getStartTimestamp(),
						inforQuery.getEndTimestamp(), inforQuery.getInformationSort(), inforQuery.getInformationLv(),
						 "%" + inforQuery.getKey() + "%",
						inforQuery.getCurFLow(), inforQuery.getInformationType(),finsihName,inforQuery.getStructure(),inforQuery.getStartCommitTime(),inforQuery.getEndCommitTime(),(inforQuery.getQualityId()),(inforQuery.getCompleteId()));
				
			}else {
				
				hql = "select DISTINCT  " + str
						+ "from Information inforTable,InformationFlow infoFLowTable  where   infoFLowTable.informationId=inforTable.id     "+subTime+"  and inforTable.createTime BETWEEN ? AND ? and  inforTable.informationSortId like ? and inforTable.informationClassificationId like ?  and inforTable.informationProfile like ? and inforTable.flowId like ? and inforTable.informationClassificationId like ?"
						+ intputUserString+"  and inforTable.zeRenPerSonNames like ? and inforTable.prisonId like ? and infoFLowTable.createTime BETWEEN ? AND ?    "
						+ " "+port+" "+queryBySouce+pString+" order by inforTable.createTime desc   ";
				noSelct =" inforTable.id) from Information inforTable,InformationFlow infoFLowTable where    infoFLowTable.informationId=inforTable.id "+subTime+"   and inforTable.createTime BETWEEN ? AND ? and  inforTable.informationSortId like ? and inforTable.informationClassificationId like ?  and inforTable.informationProfile like ? and inforTable.flowId like ? and inforTable.informationClassificationId like ? "
						+ intputUserString+"  and inforTable.zeRenPerSonNames like ? and inforTable.prisonId like ? and infoFLowTable.createTime  BETWEEN ? AND ?   "
						+ "  "+port+" "+queryBySouce+pString+"   order by inforTable.createTime desc ";
				p = super.splitPageQuerySelect(hql, p, noSelct,
						inforQuery.getStartTimestamp(),
						inforQuery.getEndTimestamp(), inforQuery.getInformationSort(), inforQuery.getInformationLv(),
						 "%" + inforQuery.getKey() + "%",
						inforQuery.getCurFLow(), inforQuery.getInformationType(),finsihName,inforQuery.getStructure(),inforQuery.getStartCommitTime(),inforQuery.getEndCommitTime());
				
			}
		}else if (inforQuery.getInformationJudge().equals("1")) {
			
				hql = "select DISTINCT " + str
						+ "from Information inforTable,InformationFlow infoFLowTable,CommentRecord commentTable,EvaluationRecord evaluationTable  where evaluationTable.informationId=inforTable.id and commentTable.informationId=inforTable.id and  infoFLowTable.informationId=inforTable.id "+subTime+"     and inforTable.createTime BETWEEN ? AND ? and  inforTable.informationSortId like ? and inforTable.informationClassificationId like ?  and inforTable.informationProfile like ? and inforTable.flowId like ? and inforTable.informationClassificationId like ?"
						+ intputUserString+" and inforTable.zeRenPerSonNames like ? and inforTable.prisonId like ? and infoFLowTable.createTime BETWEEN ? AND ? and commentTable.informationQualityId like ? and commentTable.taskCompletionId like ?  "
						+ " "+port+" "+queryBySouce+pString+" order by inforTable.createTime desc group by inforTable.id";
				noSelct =" inforTable.id) from Information inforTable,InformationFlow infoFLowTable, CommentRecord commentTable,EvaluationRecord evaluationTable  where evaluationTable.informationId=inforTable.id and  commentTable.informationId=inforTable.id and infoFLowTable.informationId=inforTable.id   "+subTime+"  and inforTable.createTime BETWEEN ? AND ? and  inforTable.informationSortId like ? and inforTable.informationClassificationId like ?  and inforTable.informationProfile like ? and inforTable.flowId like ? and inforTable.informationClassificationId like ? "
						+ intputUserString+"  and inforTable.zeRenPerSonNames like ? and inforTable.prisonId like ? and infoFLowTable.createTime  BETWEEN ? AND ?  and commentTable.informationQualityId like ? and commentTable.taskCompletionId like ?"
						+ " "+port+" "+queryBySouce+pString+"   order by inforTable.createTime desc group by inforTable.id";
				p = super.splitPageQuerySelect(hql, p, noSelct,
						inforQuery.getStartTimestamp(),
						inforQuery.getEndTimestamp(), inforQuery.getInformationSort(), inforQuery.getInformationLv(),
						 "%" + inforQuery.getKey() + "%",
						inforQuery.getCurFLow(), inforQuery.getInformationType(),finsihName,inforQuery.getStructure(),inforQuery.getStartCommitTime(),inforQuery.getEndCommitTime(),(inforQuery.getQualityId()),(inforQuery.getCompleteId()));
				
			
		}else{
			if (!inforQuery.getQualityId().equals("%")||!inforQuery.getCompleteId().equals("%")) {
				
				hql = "select DISTINCT " + str
						+ "from Information inforTable,InformationFlow infoFLowTable,CommentRecord commentTable,EvaluationRecord evaluationTable  where  evaluationTable.informationId!=inforTable.id and commentTable.informationId=inforTable.id and  infoFLowTable.informationId=inforTable.id   "+subTime+"  and  infoFLowTable.flowId<=10    and inforTable.createTime BETWEEN ? AND ? and  inforTable.informationSortId like ? and inforTable.informationClassificationId like ? and   inforTable.informationProfile like ? and inforTable.flowId like ? and inforTable.informationClassificationId like ?"
						+ intputUserString+"  and inforTable.zeRenPerSonNames like ? and inforTable.prisonId like ? and infoFLowTable.createTime BETWEEN ? AND ? and commentTable.informationQualityId like ? and commentTable.taskCompletionId like ?  "
						+ " "+port+" "+queryBySouce+pString+" order by inforTable.createTime desc group by inforTable.id";
				noSelct =" inforTable.id) from Information inforTable,InformationFlow infoFLowTable, CommentRecord commentTable,EvaluationRecord evaluationTable  where  evaluationTable.informationId!=inforTable.id and  commentTable.informationId=inforTable.id and infoFLowTable.informationId=inforTable.id "+subTime+"    and infoFLowTable.flowId<=10   and inforTable.createTime BETWEEN ? AND ? and  inforTable.informationSortId like ? and inforTable.informationClassificationId like ? and  inforTable.informationProfile like ? and inforTable.flowId like ? and inforTable.informationClassificationId like ? "
						+ intputUserString+"  and inforTable.zeRenPerSonNames like ? and inforTable.prisonId like ? and infoFLowTable.createTime  BETWEEN ? AND ?  and commentTable.informationQualityId like ? and commentTable.taskCompletionId like ?"
						+ ""+port+" "+queryBySouce+pString+"    order by inforTable.createTime desc group by inforTable.id";
				p = super.splitPageQuerySelect(hql, p, noSelct,
						inforQuery.getStartTimestamp(),
						inforQuery.getEndTimestamp(), inforQuery.getInformationSort(), inforQuery.getInformationLv(),
						 "%" + inforQuery.getKey() + "%",
						inforQuery.getCurFLow(), inforQuery.getInformationType(),finsihName,inforQuery.getStructure(),inforQuery.getStartCommitTime(),inforQuery.getEndCommitTime(),(inforQuery.getQualityId()),(inforQuery.getCompleteId()));
			}else{
				
				hql = "select DISTINCT " + str
						+ "from Information inforTable,InformationFlow infoFLowTable  where    infoFLowTable.informationId=inforTable.id   "+subTime+"  and inforTable.flowId<=10 and   inforTable.createTime BETWEEN ? AND ? and  inforTable.informationSortId like ? and inforTable.informationClassificationId like ? and   inforTable.informationProfile like ? and inforTable.flowId like ? and inforTable.informationClassificationId like ?"
						+ intputUserString+"  and inforTable.zeRenPerSonNames like ? and inforTable.prisonId like ? and infoFLowTable.createTime BETWEEN ? AND ?   "
						+ " "+port+" "+queryBySouce+pString+" order by inforTable.createTime desc group by inforTable.id";
				noSelct =" inforTable.id) from Information inforTable,InformationFlow infoFLowTable   where   infoFLowTable.informationId=inforTable.id   "+subTime+"  and inforTable.flowId<=10 and inforTable.createTime BETWEEN ? AND ? and  inforTable.informationSortId like ? and inforTable.informationClassificationId like ?  and inforTable.informationProfile like ? and inforTable.flowId like ? and inforTable.informationClassificationId like ? "
						+ intputUserString+"  and inforTable.zeRenPerSonNames like ? and inforTable.prisonId like ? and infoFLowTable.createTime  BETWEEN ? AND ?  "
						+ " "+port+" "+queryBySouce+pString+"   order by inforTable.createTime desc group by inforTable.id";
				
				p = super.splitPageQuerySelect(hql, p, noSelct,
						inforQuery.getStartTimestamp(),
						inforQuery.getEndTimestamp(), inforQuery.getInformationSort(), inforQuery.getInformationLv(),
						 "%" + inforQuery.getKey() + "%",
						inforQuery.getCurFLow(), inforQuery.getInformationType(),finsihName,inforQuery.getStructure(),inforQuery.getStartCommitTime(),inforQuery.getEndCommitTime());

			}
			//(( infoFLowTable.endTime BETWEEN ? AND ? and infoFLowTable.flowId =?) or( infoFLowTable.endTime BETWEEN ? AND ? and infoFLowTable.flowId =? ) or( infoFLowTable.endTime BETWEEN ? AND ? and infoFLowTable.flowId =? ) or( infoFLowTable.endTime BETWEEN ? AND ? and infoFLowTable.flowId =?   ) or (inforTable.flowId <= 1) or (inforTable.flowId >= 6) )
			//inforQuery.getFirstStartTime(),inforQuery.getFirstEndTime(),ConfigStatic.FLOWTABLE.get("FirstCheck"),
			//inforQuery.getReCheckStartTime(),inforQuery.getResearchEndTime(),ConfigStatic.FLOWTABLE.get("ReCheck"),
			//inforQuery.getCheckStartTime(),inforQuery.getCheckEndTime(),ConfigStatic.FLOWTABLE.get("Check"),
			//inforQuery.getResearchStartTime(),inforQuery.getResearchEndTime(),ConfigStatic.FLOWTABLE.get("InfoResearch"),
		}
		p=getUserNameByInfoUserId(p);
		return p;
	
	}
	
	
//and inforTable.inputPersonID like ? and inforTable.zeRenPersonId like ?
	//,"%,"+inforQuery.getIntputName()+",%","%,"+inforQuery.getFinisPerson()+",%"
	@Override
	public List<FirstCheckExcel> getIinformationById(int[] idArray) {
		StringBuffer idStr = new StringBuffer();
		for (int i = 0; i < idArray.length; i++) {
			if (i < idArray.length - 1) {
				idStr.append(idArray[i] + ",");
			} else {
				idStr.append(idArray[i]);
			}
		}
		String str = " new com.yuxi.Entity.FirstCheckExcel(inforTable.informationConternt, inforTable.informationClassificationNames,inforTable.mesure, inforTable.standard, inforTable.taskDispatchName, inforTable.taskDispatchTime, inforTable.zeRenTime, inforTable.taskCompletion, inforTable.zeRenPerSonNames, inforTable.zeRenRemark)";
		String hql = "select " + str + " from Information inforTable where inforTable.id in(" + idStr.toString() + ")";
		List list = super.find(hql);
		if (list.size() > 0 && list != null) {
			return list;
		}
		return null;
	}

	@Override
	public Page<Information> getAllInfoList(InformationQuery userquesy, Page<Information> p,String pId) {
		try {
			String  intputUserString="";
			if (userquesy.getUserId().equals("%")) {
				intputUserString=" ";
			}else{
				intputUserString=" and (inputPerSonNames like "+"'%,"+userquesy.getIntputName()+",%'"+" or userId ="+userquesy.getUserId()+ ") ";

			}
			String[] sourceStr;
			String queryBySouce=" ";
			if (userquesy.getInformationSource().equals("%")) {
				queryBySouce=" ";
			}else{
				sourceStr=userquesy.getInformationSource().split(",");
				for (int i = 0; i < sourceStr.length; i++) {
					queryBySouce+="  and informationSourceID like"+" '%,"+sourceStr[i]+",%'  ";
				}
			}//+" "+queryBySouce//"%," + inforQuery.getInformationSource() + ",%",
			String port;
			if (userquesy.getSalfPort().equals("%")) {
				port="  ";
			}else{
				port=" and safetyPortId in("+userquesy.getSalfPort()+")";
			}
			String hql = "from Information  where createTime BETWEEN ? AND ? and  informationSortId like ? and informationClassificationId like ?  and informationProfile like ? and flowId like ? and prisonId=? " +" "+queryBySouce +intputUserString+"  order by createTime desc";
			p = super.splitPageQuery(hql, p, userquesy.getStartTimestamp(), userquesy.getEndTimestamp(),
					userquesy.getInformationSort(), userquesy.getInformationLv(),
					"%," +  "%" + userquesy.getKey() + "%",
					userquesy.getCurFLow(),pId);
			logger.info("查询所有信息成功");
			return p;
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("查询所有信息失败");
			return null;
		}
	}
	

	@Override
	public InfoCount getAllFlowCount(UserInfo u,UserPowerView power) {	
		InfoCount rs = new InfoCount();		
		int portId =power.getMaxStructure().getId();
		String sql = "select count(id) as infoManageCunt from Information where flowId=? ";
		// 信息管理
		Integer i = super.execute(sql + " and userId=?", ConfigStatic.FLOWTABLE.get("InfoManage"), u.getUserId());
		rs.setInfoMange(i);
		// 信息初审
		List<InformationPort> userPortPower=power.getPowerPort();
		StringBuilder portStr=new StringBuilder("(");
		for(int i1=0;i1<userPortPower.size();i1++){
			if(i1>0){portStr.append(",");}			
			portStr.append(userPortPower.get(i1).getId());
		}
		portStr.append(")");
		Integer fi=0;
		if(userPortPower.size()!=0){
			 fi= super.execute(sql + "and  prisonId = ? and safetyPortId in "+portStr.toString(),ConfigStatic.FLOWTABLE.get("FirstCheck"), portId
				);
		}
		
		rs.setFirstCheck(fi);
		
		// 复核
		Integer ri = super.execute(sql + " and prisonId = ?", ConfigStatic.FLOWTABLE.get("ReCheck"), portId);
		rs.setRecheck(ri);
		// 审核
		Integer ci = super.execute(sql + " and prisonId = ?", ConfigStatic.FLOWTABLE.get("Check"), portId);
		rs.setCheck(ci);
		// 信息研判
		Integer iri=0;
		if(userPortPower.size()!=0){
			iri= super.execute(sql + " and  prisonId = ? and safetyPortId in "+portStr.toString(), ConfigStatic.FLOWTABLE.get("InfoResearch"),portId
					);
		}		
		rs.setReSeach(iri);
		

		// 任务派遣
		Integer tiri = super.execute(sql + " and prisonId = ?", ConfigStatic.FLOWTABLE.get("TaskDispatch"), portId);
		rs.setTaskDispatch(tiri);
		// 即时任务派遣
		Integer ctiri = super.execute(sql + " and prisonId = ?", ConfigStatic.FLOWTABLE.get("CurTaskDispatch"), portId);
		rs.setCurTaskDispatch(ctiri);
		// 待完成的任务
		Integer dctiri = super.execute("select count(id) from TaskDispatch  where personLiableId =? and status=0   ",
				u.getUserId());
		rs.setTaskDo(dctiri);
		// 待点评的任务
		Integer comment = super.execute("SELECT COUNT(id) from Information information where (information.flowId<? and information.id not in(SELECT info.id from Information info,CommentRecord record where record.informationId=info.id ) or information.flowId=?) AND information.prisonId=?",ConfigStatic.FLOWTABLE.get("InfoComment"), ConfigStatic.FLOWTABLE.get("InfoComment"), portId);
		rs.setComment(comment);
		// 待评价的任务
		Integer rate = super.execute("SELECT COUNT(*) from (SELECT COUNT(oneInfo.id) FROM Information as oneInfo,Informationflow flow  where  flow.informationId=oneInfo.id AND oneInfo.id not in("
				+"SELECT a.informationId from EvaluationRecord  as a  where a.userId=?) GROUP BY oneInfo.id) a",u.getUserId());
		rs.setRete(rate);
		Integer timeOut = super.execute("select count(task.id) from TaskDispatch as task,Information as oneInfo  where oneInfo.id=task.informationId and  task.taskTime <? and task.status=0 and oneInfo.prisonId = ?  ",
				System.currentTimeMillis(),portId);
		rs.setTimeOut(timeOut);
		
		Integer queryComment=super.execute("SELECT COUNT(oneInfo.id) FROM Information as oneInfo,CommentRecord record where oneInfo.id=record.informationId AND oneInfo.id not in("
				+"SELECT b.informationId from CommentRecord  as a,CommentRecordBrowse as b where a.informationId=b.informationId and b.userId=?) and (oneInfo.userId =? or oneInfo.zeRenPersonId like ? or oneInfo.inputPersonID like ?  )",u.getUserId(),u.getUserId(),"%,"+u.getUserId()+",%","%,"+u.getUserId()+",%");
		rs.setQueryComment(queryComment);
		
		Integer queryEvaluate=super.execute(" SELECT COUNT(*) FROM  (SELECT  DISTINCT oneInfo.id FROM Information as oneInfo,EvaluationRecordBrowse record where oneInfo.id=record.informationId AND record.userId=? and record.isLook=? GROUP BY oneInfo.id) as b",u.getUserId(),0);
		rs.setQueryEvaluate(queryEvaluate);
		//民警待评价
		Integer waitRateCount=super.execute("select count(*) from OwnWordRecord where state=0 and prisonId=?",portId);
		rs.setWaitRateCount(waitRateCount);
		//民警待查阅
		Integer waitCount=super.execute("select count(*) FROM  OwnWordRecord where state=1 and (createUserId=? or userBId=?) and id NOT in(SELECT b.recordId FROM OwnWordRecord as a,OwnwordRecordBorwser as b WHERE a.id=b.recordId and b.userId=?) ", u.getUserId(),u.getUserId(),u.getUserId());
		rs.setWaitCount(waitCount);
			

		
		return rs;
	}

	@Override
	public Page<Information> getAreadyDisInfo(InformationQuery userquesy, Page<Information> p, UserInfo u) {
		try {
			String  intputUserString="";
			if (userquesy.getUserId().equals("%")) {
				intputUserString=" ";
			}else{
				intputUserString=" and (infoTable.inputPerSonNames like "+"'%,"+userquesy.getIntputName()+",%'"+" or infoTable.userId ="+userquesy.getUserId()+ ") ";

			}
			String port;
			String[] sourceStr;
			String queryBySouce=" ";
			
			
			if (userquesy.getInformationSource().equals("%")) {
				queryBySouce=" ";
			}else{
				sourceStr=userquesy.getInformationSource().split(",");
				for (int i = 0; i < sourceStr.length; i++) {
					queryBySouce+="  and infoTable.informationSourceID like"+" '%,"+sourceStr[i]+",%'  ";
				}
			}//+" "+queryBySouce//"%," + inforQuery.getInformationSource() + ",%",
			if (userquesy.getSalfPort().equals("%")) {
				port="  ";
			}else{
				port=" and infoTable.safetyPortId in("+userquesy.getSalfPort()+")";
			}
			StringBuilder str = new StringBuilder();
			str.append(
					"select new Information(infoTable.id, infoTable.informationAccount, infoTable.informationType, infoTable.informationSourceID, infoTable.informationSourceNames, infoTable.inputPersonID, infoTable.inputPerSonNames, infoTable.informationProfile, infoTable.informationConternt, infoTable.mesure, infoTable.standard, infoTable.informationClassificationId, infoTable.informationSortId, infoTable.informationClassificationNames, infoTable.informationSortNames, infoTable.appendix, infoTable.taskCompletion, infoTable.safetyPortId, infoTable.safetyPortNames, infoRecordTable1.time,infoTable.userId, infoTable.flowId, infoTable.flowName, infoTable.prisonId, infoTable.zeRenPersonId, infoTable.zeRenPerSonNames, infoTable.zeRenTime, infoTable.zeRenRemark, infoTable.taskDispatchName, infoTable.taskDispatchTime)");

			// p=super.splitPageQuery(str.toString(),p,userquesy.getStartTimestamp(),userquesy.getEndTimestamp(),userquesy.getInformationSort(),userquesy.getInformationLv(),"%,"+userquesy.getInformationSource()+",%","%"+userquesy.getKey()+"%",userquesy.getCurFLow(),u.getUserId(),ConfigStatic.DOTYPETABLE.get("InformationDispatch"),"信息调配成功");
			String noSelct = " from Information as infoTable,InformationOperationRecord as infoRecordTable1 where infoTable.id=infoRecordTable1.infomationId and infoRecordTable1.time BETWEEN ? AND ? and  infoTable.informationSortId like ? and infoTable.informationClassificationId like ? and   infoTable.informationProfile like ? and infoTable.flowId like ? and infoRecordTable1.userID=? and infoRecordTable1.doType=? and  infoRecordTable1.doRemark=?"
					+intputUserString+port+queryBySouce +" and infoTable.zeRenPerSonNames like  ? and infoTable.prisonId like ?  order by infoRecordTable1.time desc";
			str.append(noSelct);
			p = super.splitPageQuerySlect(str.toString(), p, noSelct, userquesy.getStartTimestamp(),
					userquesy.getEndTimestamp(), userquesy.getInformationSort(), userquesy.getInformationLv(),
					 "%" + userquesy.getKey() + "%",
					userquesy.getCurFLow(), u.getUserId(), ConfigStatic.DOTYPETABLE.get("InformationDispatch"),
					"信息调配成功","%,"+userquesy.getFinisPerson()+",%",userquesy.getStructure());
			logger.info("查询所有信息成功");
			p=getUserNameByInfoUserId(p);
			return p;
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("查询所有信息失败");
			return null;
		}
	}

	@Override
	public Page<TaskInformationView> getUserDispatchList(InformationQuery inforQuery, Page p, int userId) {
		String str = " new com.yuxi.Entity.TaskInformationView(inforTable.id, inforTable.userId,inforTable.informationAccount, inforTable.informationType, inforTable.safetyPortId,inforTable.informationSourceID,inforTable.informationSourceNames, inforTable.inputPerSonNames, inforTable.informationProfile, inforTable.informationConternt, inforTable.mesure, inforTable.standard, inforTable.informationClassificationId, inforTable.informationClassificationNames, inforTable.informationSortNames, inforTable.safetyPortNames, inforTable.createTime, taskDisTable.perSonLiableName, inforTable.zeRenTime, taskDisTable.id, taskDisTable.personDispatchName,taskDisTable.remark,taskDisTable.status,taskDisTable.type,inforTable.flowId,inforTable.flowName)";
		String hql;
		String noSelct;
		int isFinish=0;
		String isFinishStr="";
		String[] sourceStr;
		String queryBySouce=" ";
		if (inforQuery.getInformationSource().equals("%")) {
			queryBySouce=" ";
		}else{
			sourceStr=inforQuery.getInformationSource().split(",");
			for (int i = 0; i < sourceStr.length; i++) {
				queryBySouce+="  and inforTable.informationSourceID like"+" '%,"+sourceStr[i]+",%'  ";
			}
		}//+" "+queryBySouce//"%," + inforQuery.getInformationSource() + ",%",
		String  intputUserString="";
		if (inforQuery.getUserId().equals("%")) {
			intputUserString=" ";
		}else{
			intputUserString=" and (inforTable.inputPerSonNames like "+"'%,"+inforQuery.getIntputName()+",%'"+" or inforTable.userId ="+inforQuery.getUserId()+ ") ";

		}
		
		String port;
		if (inforQuery.getSalfPort().equals("%")) {
			port="  ";
		}else{
			port=" and safetyPortId in("+inforQuery.getSalfPort()+")";
		}
		if (inforQuery.getIsFinish().equals("1")) {
			isFinishStr=" and taskDisTable.status = 1 ";
		}else if (inforQuery.getIsFinish().equals("2")) {
			isFinishStr=" and taskDisTable.status = 0 ";
		}else {
			isFinishStr="  ";
		}
		if (inforQuery.getInformationJudge().equals("%")) {
			
			hql = "select DISTINCT  " + str
					+ "  from Information inforTable,TaskDispatch taskDisTable where inforTable.id=taskDisTable.informationId and taskDisTable.personDispatchId=? and taskDisTable.createTime BETWEEN ? AND ? and  inforTable.informationSortId like ?  and inforTable.informationProfile like ?  and inforTable.informationClassificationId like ?   and taskDisTable.type=? "
					+ intputUserString+ "and taskDisTable.perSonLiableName like ? and inforTable.prisonId like ? and taskDisTable.taskTime BETWEEN ? AND ?  "+isFinishStr+ " "+port+" "+queryBySouce+"  order by inforTable.createTime desc";
			noSelct = "inforTable.id) from Information as inforTable,TaskDispatch as taskDisTable where inforTable.id=taskDisTable.informationId  and taskDisTable.personDispatchId=?  and taskDisTable.createTime BETWEEN ? AND ? and  inforTable.informationSortId like ?  and inforTable.informationProfile like ?  and inforTable.informationClassificationId like ?  and taskDisTable.type=? "
					+intputUserString+ " and taskDisTable.perSonLiableName like ? and inforTable.prisonId like ? and taskDisTable.taskTime BETWEEN ? AND ?  "+isFinishStr+ " "+port+" "+queryBySouce+"  order by inforTable.createTime desc";
			p = super.splitPageQuerySelect(hql, p, noSelct, userId, inforQuery.getStartTimestamp(),
					inforQuery.getEndTimestamp(), inforQuery.getInformationSort(),
					 "%" + inforQuery.getKey() + "%",
					 inforQuery.getInformationLv(),inforQuery.getTaskType(),inforQuery.getFinisPerson(),inforQuery.getStructure(),inforQuery.getStartFinishTime(),inforQuery.getEndFinishTime());
			
		}else if (inforQuery.getInformationJudge().equals("1")) {
			
			 hql = "select  DISTINCT  " + str
					+ " from Information inforTable,TaskDispatch taskDisTable where inforTable.id=taskDisTable.informationId and taskDisTable.personDispatchId=? and taskDisTable.createTime BETWEEN ? AND ? and  inforTable.informationSortId like ?  and inforTable.informationProfile like ?  and inforTable.informationClassificationId like ?  and taskDisTable.type=? "
					+ intputUserString+ "and taskDisTable.perSonLiableName like ? and inforTable.prisonId like ? and taskDisTable.taskTime like ?  "+isFinishStr+ " "+port+" "+queryBySouce+"  order by inforTable.createTime desc";
			 noSelct = "inforTable.id) from Information as inforTable,TaskDispatch as taskDisTable where inforTable.id=taskDisTable.informationId  and taskDisTable.personDispatchId=?  and taskDisTable.createTime BETWEEN ? AND ? and  inforTable.informationSortId like ?  and inforTable.informationProfile like ?  and inforTable.informationClassificationId like ?  and taskDisTable.type=? "
					+ intputUserString+ " and taskDisTable.perSonLiableName like ? and inforTable.prisonId like ? and taskDisTable.taskTime like ?  "+isFinishStr+ ""+port+" "+queryBySouce+"  order by inforTable.createTime desc";
			p = super.splitPageQuerySelect(hql, p, noSelct, userId, inforQuery.getStartTimestamp(),
					inforQuery.getEndTimestamp(), inforQuery.getInformationSort(),
					 "%" + inforQuery.getKey() + "%",
					 inforQuery.getInformationLv(),inforQuery.getTaskType(),inforQuery.getFinisPerson(),inforQuery.getStructure(),Long.valueOf("3502800000000"));
			
		}else {
			
			 hql = "select DISTINCT  " + str
					+ " from Information inforTable,TaskDispatch taskDisTable where inforTable.id=taskDisTable.informationId and taskDisTable.personDispatchId=? and taskDisTable.createTime BETWEEN ? AND ? and  inforTable.informationSortId like ? and inforTable.informationProfile like ?  and inforTable.informationClassificationId like ?   and taskDisTable.type=? "
					+ intputUserString+ " and taskDisTable.perSonLiableName like ? and inforTable.prisonId like ? and taskDisTable.taskTime BETWEEN ? AND ? and taskDisTable.taskTime != ?  "+isFinishStr+ " "+port+" "+queryBySouce+"   order by inforTable.createTime desc";
			 noSelct = "inforTable.id) from Information as inforTable,TaskDispatch as taskDisTable where inforTable.id=taskDisTable.informationId  and taskDisTable.personDispatchId=?  and taskDisTable.createTime BETWEEN ? AND ? and  inforTable.informationSortId like ?  and inforTable.informationProfile like ?  and inforTable.informationClassificationId like ?  and taskDisTable.type=? "
					+ intputUserString+ " and taskDisTable.perSonLiableName like ? and inforTable.prisonId like ? and taskDisTable.taskTime BETWEEN ? AND ? and taskDisTable.taskTime != ?   "+isFinishStr+ " "+port+" "+queryBySouce+" order by inforTable.createTime desc";
			p = super.splitPageQuerySelect(hql, p, noSelct, userId, inforQuery.getStartTimestamp(),
					inforQuery.getEndTimestamp(), inforQuery.getInformationSort(),
					 "%" + inforQuery.getKey() + "%",
					 inforQuery.getInformationLv(),inforQuery.getTaskType(),inforQuery.getFinisPerson(),inforQuery.getStructure(),inforQuery.getStartFinishTime(),inforQuery.getEndFinishTime(),Long.valueOf("3502800000000"));

		}
//		List<TaskInformationView> informations=p.getList();
//		for (Iterator iterator = informations.iterator(); iterator.hasNext();) {
//			TaskInformationView information = (TaskInformationView) iterator.next();
//			
//			information.setUserName(UserTableStatic.findUserById(Integer.valueOf(information.getUserId())).getUserName());
//		}
//		p.setList(informations);
		p=ditinctInformation(p);
		p=getUserNameByTaskViewUserId(p);
		return p;
	}

	@Override
	public boolean delInformationById(Integer id) {
		super.delete("delete from Information where id=?", id);
		return true;
	}

	@Override
	public Page<Information> getCanTaskDisList(InformationQuery userquesy, Page<Information> p, String pId) {
		try {
			String[] sourceStr;
			String queryBySouce=" ";
			if (userquesy.getInformationSource().equals("%")) {
				queryBySouce=" ";
			}else{
				sourceStr=userquesy.getInformationSource().split(",");
				for (int i = 0; i < sourceStr.length; i++) {
					queryBySouce+="  and informationSourceID like"+" '%,"+sourceStr[i]+",%'  ";
				}
			}//+" "+queryBySouce//"%," + inforQuery.getInformationSource() + ",%",
			String hql = "from Information  where createTime BETWEEN ? AND ? and  informationSortId like ? and informationClassificationId like ?  and informationProfile like ? and flowId >1 and flowId<5 and prisonId=?"+" "+queryBySouce+" order by createTime desc";
			p = super.splitPageQuery(hql, p, userquesy.getStartTimestamp(), userquesy.getEndTimestamp(),
					userquesy.getInformationSort(), userquesy.getInformationLv(),
					 "%" + userquesy.getKey() + "%",
					pId);			
			return p;
		} catch (Exception e) {
			e.printStackTrace();			
			return null;
		}
	}

	@Override
	public List<Map<String, Object>> getPriosnALlData(DateQuery query) {
		StringBuilder str=new StringBuilder();
		str.append("SELECT a.*,b.`name` from (select COUNT(id) as infoCount,");
		str.append("prisonId,safetyPortId,safetyPortNames,");
		str.append("sum(case when flowId ='1' then 1 else 0 end) as infoManage ,");
		str.append("sum(case when flowId ='2' then 1 else 0 end) as firstCheck ,");
		str.append("sum(case when flowId ='3' then 1 else 0 end) as reCheck ,");
		str.append("sum(case when flowId ='4' then 1 else 0 end) as infoCheck,");
		str.append("sum(case when flowId ='5' then 1 else 0 end) as infoReSeach ,");
		str.append("sum(case when flowId ='6' then 1 else 0 end) as taskDis ,");
		str.append("sum(case when flowId ='7' then 1 else 0 end) as curTaskDis,");
		str.append("sum(case when flowId ='8' then 1 else 0 end) as taskFinsh ,");
		str.append("sum(case when flowId ='9' then 1 else 0 end) as infoComment,");
		str.append("sum(case when flowId ='10' then 1 else 0 end) as infoRate,");
		str.append("sum(case when flowId ='11' then 1 else 0 end) as infoFinsh");
		str.append(" from information where createTime BETWEEN ? and ? ");
		str.append("GROUP BY prisonId,safetyPortId) as a ,prisonstructure  as b where a.prisonId =b.id  order by b.id");
		System.out.println(str.toString());
		return (List<Map<String, Object>>)super.executeSql(str.toString(),query.getStarTime(),query.getEndTime());
	}
	
	

	@Override
	public List<Map<String, Object>> getPrisonAllDataByMonth() {
		StringBuilder str=new StringBuilder();
		str.append("SELECT a.*,b.`name` from (select COUNT(id) as infoCount,");
		str.append("prisonId,safetyPortId,safetyPortNames,FROM_UNIXTIME(createTime/1000, '%m') as monthName");
//		str.append("sum(case when flowId ='1' then 1 else 0 end) as infoManage ,");
//		str.append("sum(case when flowId ='2' then 1 else 0 end) as firstCheck ,");
//		str.append("sum(case when flowId ='3' then 1 else 0 end) as reCheck ,");
//		str.append("sum(case when flowId ='4' then 1 else 0 end) as infoCheck,");
//		str.append("sum(case when flowId ='5' then 1 else 0 end) as infoReSeach ,");
//		str.append("sum(case when flowId ='6' then 1 else 0 end) as taskDis ,");
//		str.append("sum(case when flowId ='7' then 1 else 0 end) as curTaskDis,");
//		str.append("sum(case when flowId ='8' then 1 else 0 end) as taskFinsh ,");
//		str.append("sum(case when flowId ='9' then 1 else 0 end) as infoComment,");
//		str.append("sum(case when flowId ='10' then 1 else 0 end) as infoRate,");
//		str.append("sum(case when flowId ='11' then 1 else 0 end) as infoFinsh");
		str.append(" from information ");
		str.append("GROUP BY prisonId,safetyPortId,FROM_UNIXTIME(createTime/1000, '%m')) as a ,prisonstructure  as b where a.prisonId =b.id ");
		return (List<Map<String, Object>>)super.executeSql(str.toString());
	}

	@Override
	public List<Information> getInforList(InformationQuery query, Integer userId) {
		StringBuilder str=new StringBuilder("");
		if(!query.getInformationSource().equals("%")){
			String[] source=query.getInformationSource().split(",");
			str.append(" and (");
			for(int i=0;i<source.length;i++){
				if(i>=1){
					str.append(" or ");
				}
				str.append(" informationSourceID like %,"+source[i]+",% ");
			}
			str.append(")");
		}
	
				
		String hql="from Information where  userId=? and createTime BETWEEN ? and ? and "
				+ "  safetyPortId=? "+ str.toString();
		return find(hql,userId,query.getStartTimestamp(),query.getEndTimestamp(),query.getSalfPort());
	}
	
	@Override
	public Page<TaskInformationView> getAllTimeOutInfoList(InformationQuery inforQuery, Page p, int userId, int state) {
		String  intputUserString="";
		if (inforQuery.getUserId().equals("%")) {
			intputUserString=" ";
		}else{
			intputUserString=" and (inforTable.inputPerSonNames like "+"'%,"+inforQuery.getIntputName()+",%'"+" or inforTable.userId ="+inforQuery.getUserId()+ ") ";

		}
		String port;
		if (inforQuery.getSalfPort().equals("%")) {
			port="  ";
		}else{
			port=" and inforTable.safetyPortId in("+inforQuery.getSalfPort()+")";
		}
		String[] sourceStr;
		String queryBySouce=" ";
		if (inforQuery.getInformationSource().equals("%")) {
			queryBySouce=" ";
		}else{
			sourceStr=inforQuery.getInformationSource().split(",");
			for (int i = 0; i < sourceStr.length; i++) {
				queryBySouce+="  and inforTable.informationSourceID like"+" '%,"+sourceStr[i]+",%'  ";
			}
		}//+" "+queryBySouce
		String str = " new com.yuxi.Entity.TaskInformationView(inforTable.id, inforTable.userId,inforTable.informationAccount, inforTable.informationType,inforTable.safetyPortId,inforTable.informationSourceID, inforTable.informationSourceNames, inforTable.inputPerSonNames, inforTable.informationProfile, inforTable.informationConternt, inforTable.mesure, inforTable.standard, inforTable.informationClassificationId, inforTable.informationClassificationNames, inforTable.informationSortNames, inforTable.safetyPortNames, inforTable.createTime, inforTable.zeRenPerSonNames, inforTable.zeRenTime, taskDisTable.id, taskDisTable.personDispatchName,taskDisTable.remark,taskDisTable.status,taskDisTable.type,inforTable.flowId,inforTable.flowName)";
		String hql = "select distinct  " + str
				+ " from Information inforTable,TaskDispatch taskDisTable where inforTable.id=taskDisTable.informationId and taskDisTable.status=? and taskDisTable.taskTime<? and taskDisTable.createTime BETWEEN ? AND ? "
				+intputUserString +" and  inforTable.informationSortId like ?  and inforTable.informationProfile like ?  and inforTable.informationClassificationId like ?   "
				+ "and inforTable.prisonId like ?  "+port+" "+queryBySouce+"  order by inforTable.createTime desc";
		String noSelct = "from Information as inforTable,TaskDispatch as taskDisTable where inforTable.id=taskDisTable.informationId and  taskDisTable.status=?  and taskDisTable.taskTime<?  "
				+ "and taskDisTable.createTime BETWEEN ? AND ?  "
				+ intputUserString +" and inforTable.informationSortId like ?  and inforTable.informationProfile like ?  and inforTable.informationClassificationId like ?  "
				+ " and inforTable.prisonId like ?  "+port+" "+queryBySouce+"  order by inforTable.createTime desc";
		p = super.splitPageQuerySlect(hql, p, noSelct, 0, System.currentTimeMillis(), inforQuery.getStartTimestamp(),
				inforQuery.getEndTimestamp(), inforQuery.getInformationSort(),
				 "%" + inforQuery.getKey() + "%",
				 inforQuery.getInformationLv(),inforQuery.getStructure());
		p=getUserNameByTaskViewUserId(p);
		return p;
	}


	


@Override
	public void deleteInformationBYId(Integer id) {
		super.delete("DELETE FROM Information WHERE id=?", id);
		super.delete("DELETE FROM CommentRecord WHERE informationId=?", id);
		super.delete("DELETE FROM CommentRecordBrowse WHERE informationId=?", id);
		super.delete("DELETE FROM EvaluationRecord WHERE informationId=?", id);
		super.delete("DELETE FROM EvaluationRecordBrowse WHERE informationId=?", id);
		super.delete("DELETE FROM InforChangeRecord WHERE infoId=?", id);
		super.delete("DELETE FROM InformationFlow WHERE informationId=?", id);
		super.delete("DELETE FROM InformationOperationRecord WHERE infomationId=?", id);
		super.delete("DELETE FROM ModifyInformationRecord WHERE informationId=?", id);
		super.delete("DELETE FROM TaskDispatch WHERE informationId=?", id);
	}

@Override
public Page<TaskInformationView> getUserNameByTaskViewUserId(Page p) {
	List<TaskInformationView> informations=p.getList();
	for (Iterator iterator = informations.iterator(); iterator.hasNext();) {
		TaskInformationView information = (TaskInformationView) iterator.next();
		
		information.setUserName(UserTableStatic.findUserById(Integer.valueOf(information.getUserId())).getUserName());
	}
	p.setList(informations);
	return p;
}

@Override
public Page<Information> getUserNameByInfoUserId(Page p) {
	List<Information> informations=p.getList();
	for (Iterator iterator = informations.iterator(); iterator.hasNext();) {
		Information information = (Information) iterator.next();
		
		information.setUserName(UserTableStatic.findUserById(Integer.valueOf(information.getUserId())).getUserName());
	}
	p.setList(informations);
	return p;
}


private Page ditinctInformation(Page p) {
	// TODO Auto-generated method stub
	List<TaskInformationView> informations=p.getList();
	List<TaskInformationView> rsList=new ArrayList<TaskInformationView>();
	int size=informations.size();
	Map<Integer, Boolean> isMap=new HashMap<Integer, Boolean>();
	for (int i = 0; i < size; i++) {
		TaskInformationView array_element = informations.get(i);
		boolean is=false;
		try{
			is=isMap.get(array_element.getId());
		}catch(Exception e){
			rsList.add(array_element);
			isMap.put(array_element.getId(), true);
			is=false;
		}
	}

	p.setList(rsList);
	System.out.println(p);
	return p;
}



	
}
